<?php
require $_SERVER["DOCUMENT_ROOT"] . "/aonce_connect.php";
//require $_SERVER["DOCUMENT_ROOT"] . $parent_dir . "/funcs.php";

/*
 * Primer capa de validacion de obtencion de datos de serie si es que existe
 * Metodos POST & GET cubuertos
 */

$serie = isset($_GET["serie"]) ? $_GET["serie"] : NULL;
if($serie == NULL)
	$serie = isset($_POST["serie"]) ? $_POST["serie"] : NULL;
$esNuevaSerie=false;
if($serie == NULL){
	$err_msg = "Serie no econtrada";
	$esNuevaSerie = true;
//	redirect_error($msg);
//	printf($err_msg);
}

$artista_fields = "idartista AS id, nombreartista AS nombre";
$artista_query = "SELECT $artista_fields FROM artista;";

if($serie!=NULL){
/*
 * Queries de obtenci'on de informaci'on de la serie y sus fotos
 */
$serie_fields = "nombreserie AS nombre, artista AS artista";
$serie_query = "SELECT $serie_fields FROM serie WHERE idserie=$serie LIMIT 1;";

$picsser_fields = "idpicsser, titulopicsser AS titulo, yearpicsser AS year, materialpicsser AS material, fotopicsser AS foto";
$picsser_query = "SELECT $picsser_fields FROM picsser WHERE serie=$serie LIMIT 18;";
//echo $picsser_query;

/*
 * Conexion a DB y ejecuci'on de queries
 */
$link = conecta();
$serie_result = $link->query($serie_query);
$artista_result = $link->query($artista_query);
$picsser_result = $link->query($picsser_query);
//var_dump($link);
$link->close();
/*
 * Asociaci'on de datos de artista y serie con variables
 */
$serie_data = $serie_result->fetch_assoc();
}
else{
$link = conecta();
$artista_result = $link->query($artista_query);
$link->close();
//echo $artista_query;
}

?>
<!--Force IE6 into quirks mode with this comment tag-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Alternativa Once</title>
<link href="styleIndex.css" rel="stylesheet" type="text/css" />
<link href="styleArtista.css" rel="stylesheet" type="text/css" />
<link href="styleFormas.css" rel="stylesheet" type="text/css" />
<!-- calendar stylesheet -->
  <link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-cold-1.css" title="win2k-cold-1" />
  <!-- main calendar program -->
  <script type="text/javascript" src="js/calendar.js"></script>
  <!-- language for the calendar -->
  <script type="text/javascript" src="js/calendar-en.js"></script>
  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="js/calendar-setup.js"></script>
<script>
  function changeimage(towhat,url){
    if (document.images){
      document.images.targetimage.src=towhat.src
      gotolink=url
    }
  }
  
  function warp(){
    window.location=gotolink
  }
  
  </script>
  
  <script language="JavaScript1.1">
  var myimages=new Array()
  var gotolink="#"
  
  function preloadimages(){
    for (i=0;i<preloadimages.arguments.length;i++){
    myimages[i]=new Image()
    myimages[i].src=preloadimages.arguments[i]
    }
  }
  
  preloadimages("images/img01.gif","images/pic02.gif","images/pic03.gif","images/pic04.gif","images/pic05.gif")
</script>
</head>
<body>

<div id="framecontent">
<div class="seccioninterior">

<div id="navcontainer">
<ul>
   <li><a href="#">Terms & Conditions</a></li>
   <li><a href="#">Copyright Information</a></li>
   <li><a href="#">Privacy Policy</a></li>
   <li style="border:0"><a href="#">Sitemap</a></li>                                                    
</ul> 
</div>  

</div>
</div>

<div id="maincontent">

<?php require "head.php";?>

<h1 class="tituloNuevaConvocatoria">
<?php
if($esNuevaSerie){
		echo "Nueva Serie";
}
else
		echo "Serie $serie";
?>
</h1>
<div class="seccioninterior" style="margin-top:40px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px">
		<form enctype="multipart/form-data" action="alta_serie.php<?php if(!$esNuevaSerie) echo "?serie=$serie";?>" method="POST">
<div style="margin-bottom:10px">
  <div class="tagTituloIzquierdo">Serie:</div>
	<input name="tituloserie" type="text" class="textDerecho" value="<?php printf("%s",$serie_data['nombre']);?>"/>
</div>


<?php
if($picsser_result->num_rows !=0){
		$c=1;
	while($picsser_data = $picsser_result->fetch_assoc()){
		printf("\t<div class=\"divInfoExpoActual\">\n");
		printf("\t\t<div class=\"infoId\"> No.%d</div>\n", $c++);
		printf("\t\t<div class=\"infoDescripcion\">%s</div>\n", $picsser_data['titulo']);
		printf("\t\t<div class=\"borrarDatosExpo\"><a href=\"borra_seriepic.php?pic=%d\">[ borradme ]</a></div>\n", $picsser_data['idpicsser']);
		printf("\t</div>\n");
	}
}
?>

<div class="divNuevaExpoBottom">
	<div style="margin-bottom:10px">
			<div class="tagTituloIzquierdo">Artista:</div>
			<select name="artista">
			<?php
			if($artista_result->num_rows != 0){
				while($artista_data = $artista_result->fetch_assoc()){
					if($artista_data["id"]==$serie_data["artista"])
						printf("\t<option value=\"%s\" SELECTED>%s</option>\n", $artista_data["id"], $artista_data["nombre"]);
					else
						printf("\t<option value=\"%s\">%s</option>\n", $artista_data["id"], $artista_data["nombre"]);
				}		
			}
			?>
			</select>
	</div>
	<div class="tagTituloIzquierdo">Imagen (542 x 362):</div>
	<input type="file" name="uploadedfile[]" class="inputFileExpo">	
	<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

	<div class="tagTituloIzquierdo">Thumbnail (74 x 74):</div>
	<input type="file" name="uploadedfile[]" class="inputFileExpo">
	<input type="hidden" name="thumb_MAX_FILE_SIZE" value="10000" />
</div>

<div class="divTituloDerecho">
	<div class="divTagDerecho">
		<div class="tagTituloDerecho">T&iacute;tulo:</div>
		<input name="titulo" type="text" class="textDerechoExpo"/>
	</div>
	<div class="divTituloDerecho">
		<div class="tagTituloDerecho">A&ntilde;o:</div>
		<input name="year" type="text" class="textDerechoExpo"/>
	</div>
	<div class="divTituloDerecho">
		<div class="tagTituloDerecho">Material:</div>
		<input name="material" type="text" class="textDerechoExpo"/>
	</div>
	<div class="divTituloDerecho">
		<div class="tagTituloDerecho">Medidas:</div>
		<input name="medidas" type="text" class="textDerechoExpo"/>
	</div>
	<input type="submit" value="Guardar Cambios" />
	</form>
</div>

</div>
</div>


</body>
</html>
